const {
  zmfAccountInfoCollection
} = require('../../../common/constants')
const {
  ERROR
} = require('../../../common/error')

/**
 * 更新户信息
 * @param {Object}  params
 * @param {String}  params._id     主键
 * @param {String}  params.uid     用户id
 * @param {String}  params.used    使用字符数
 * @param {String}  params.use_up_mark	是否用尽标识
 */
module.exports = async function (params = {}) {
  const schema = {
	_id: 'string',
	uid: 'string',
	used: {
	  required: true,
	  type: 'number'
	},
	use_up_mark: {
	  required: true,
	  type: 'boolean'
	}
  }
  
  this.middleware.validate(params, schema)
  
  const {
	  _id,
	  uid,
	  type,
	  source,
	  create_date,
	  expire_date,
	  words,
	  used,
	  use_up_mark
  } = params
  
  // 数据
  let data = {
	used,
	use_up_mark
  }
  
  const accountInfoResp = await zmfAccountInfoCollection.where({uid:uid,_id:_id}).update(data)
  return {
    errCode: 0,
    userRecord: accountInfoResp
  }
}
